<template>
  <div class="login-panel">
    <h1 class="title">弘源后台管理系统</h1>
    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <!-- 账号登录的panel -->
        <el-tab-pane name="account">
          <template #label>
            <div class="label">
              <el-icon><UserFilled /></el-icon>
              <span class="text">帐号登录</span>
            </div>
          </template>
          <!-- 显示的内容 -->
          <PaneAccount ref="accountRef" />
        </el-tab-pane>
        <!-- 手机登录的panel -->
        <el-tab-pane name="phone">
          <template #label>
            <div class="label">
              <el-icon><Cellphone /></el-icon>
              <span class="text">手机登录</span>
            </div>
          </template>
          <!-- 显示的内容 -->
          <PanePhone />
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="controls">
      <el-checkbox v-model="isRemPwd" label="记住密码" size="large" />
      <el-link type="primary" :underline="false">忘记密码</el-link>
    </div>
    <el-button
      class="login-btn"
      type="primary"
      size="large"
      @click="handleLoginBtnClick"
      >立即登录</el-button
    >
  </div>
</template>

<script setup lang="ts">
// 导入的组件
import { localCache } from '@/utils/cache'
import PaneAccount from './pane-account.vue'
import PanePhone from './pane-phone.vue'
// 从vue中引入
import { ref, watch } from 'vue'

const activeName = ref('account')
const isRemPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false)
watch(isRemPwd, (newValue) => {
  localStorage.setItem('isRemPwd', JSON.stringify(newValue))
})
const accountRef = ref<InstanceType<typeof PaneAccount>>()

function handleLoginBtnClick() {
  if (activeName.value === 'account') {
    accountRef.value?.loginAction(isRemPwd.value)
  } else {
    console.log('用户在进行手机登录')
  }
}
</script>

<style lang="less" scoped>
.login-panel {
  width: 400px;
  padding: 40px;
  margin-bottom: 50px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  box-shadow: 
    0 25px 50px rgba(0, 0, 0, 0.1),
    0 15px 35px rgba(0, 0, 0, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  z-index: 10;
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-5px);
    box-shadow: 
      0 35px 65px rgba(0, 0, 0, 0.15),
      0 20px 40px rgba(0, 0, 0, 0.08),
      inset 0 1px 0 rgba(255, 255, 255, 0.6);
  }

  .title {
    text-align: center;
    margin-bottom: 30px;
    font-size: 28px;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 1px;
  }

  .tabs {
    margin-bottom: 20px;
    
    :deep(.el-tabs__header) {
      margin: 0 0 20px 0;
    }
    
    :deep(.el-tabs__nav) {
      border-radius: 12px;
      overflow: hidden;
    }
    
    :deep(.el-tabs__item) {
      padding: 15px 20px;
      transition: all 0.3s ease;
      
      &.is-active {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
      }
    }
    
    :deep(.el-tabs__content) {
      padding: 20px 0;
    }
  }

  .label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    .text {
      font-weight: 500;
    }
  }

  .controls {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    :deep(.el-checkbox) {
      .el-checkbox__label {
        color: #666;
        font-weight: 500;
      }
    }
    
    :deep(.el-link) {
      font-weight: 500;
    }
  }

  .login-btn {
    margin-top: 25px;
    width: 100%;
    height: 45px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 1px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    transition: all 0.3s ease;
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
    }
    
    &:active {
      transform: translateY(0);
    }
  }
}
</style>
